home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / progutil / stdwin.zoo / textedit / text.h < prev    next >
Encoding:
C/C++ Source or Header  |  1989-10-18  |  4.1 KB  |  124 lines

  1. /* Text Edit, definitions */
  2. /* $Header: /userfs3/amoeba/guido/src/stdwin/textedit/RCS/text.h,v 1.2 89/07/24 13:48:41 guido Exp Locker: guido $ */
  3.  
  4. /* Include header files */
  5. #include "stdwin.h"    /* Window interface */
  6. #include "tools.h"    /* Lots of useful goodies */
  7.  
  8. #ifndef LSC
  9. #define NDEBUG        /* Turn off all debugging code */
  10. #endif
  11.  
  12. #define RESERVE 256    /* Increment for gap growth */
  13. #define STARTINCR 20    /* Increment for start array growth; must be >= 1 */
  14.  
  15. /* Typedefs (for documentation only) */
  16. typedef int focpos;    /* Logical offset (not affected by gap) */
  17. typedef int bufpos;    /* Buffer offset (taking gap into account) */
  18. typedef int lineno;    /* Index into start array */
  19. typedef int coord;    /* Used to declare pairs of coordinates */
  20. typedef coord hcoord;    /* Hor. coordinate */
  21. typedef coord vcoord;    /* Ver. coordinate */
  22.  
  23. struct _textedit {
  24.     /* Drawing environment */
  25.     WINDOW *win;
  26.     coord left, top, right, bottom;
  27.     hcoord width;    /* == right-left */
  28.     TEXTATTR attr;    /* Text attributes */
  29.     vcoord vspace;    /* Vertical spacing (line height) */
  30.     hcoord tabsize;    /* Spacing of horizontal tabs */
  31.     
  32.     /* Text and focus representation */
  33.     char *buf;    /* Text buffer */
  34.     bufpos buflen;    /* Size of buffer */
  35.     bufpos gap;    /* Start of gap */
  36.     int gaplen;    /* Gap length */
  37.     focpos foc;    /* Text selection focus start */
  38.     int foclen;    /* Focus length */
  39.     bufpos *start;    /* Array of screen line starts */
  40.     lineno nlines;    /* Number of lines */
  41.     lineno nstart;    /* Number of elements of start (must be > nlines) */
  42.     hcoord aim;    /* Where vertical arrows should (try to) go */
  43.     focpos anchor;    /* Anchor position of focus drag */
  44.     focpos anchor2;    /* Other end of anchor */
  45.     tbool focprev;    /* Set if foc between lines belongs to prev line */
  46.     tbool hilite;    /* Set if focus area shown inverted */
  47.     tbool mdown;    /* Set if mouse down */
  48.     tbool dclick;    /* Set if mouse down in double click */
  49.     tbool drawing;    /* FALSE if no window operations */
  50.     
  51.     /* To optimize single char inserts */
  52.     tbool opt_valid;    /* Set if following data is valid */
  53.     tbool opt_in_first_word;/* Focus is in first word of line */
  54.     lineno opt_i;        /* Line where focus is */
  55.     coord opt_h, opt_v;    /* Caret position in window */
  56.     hcoord opt_avail;    /* White pixels at end of line */
  57.     hcoord opt_end;        /* End of line or next tab stop */
  58.     
  59.     /* NB: aim, opt_h, opt_v are in window coordinates,
  60.            i.e., tp->left or tp->top has already been added */
  61. };
  62.  
  63. /* Constants */
  64. #define UNDEF        (-1)    /* Undefined value, e.g., for aim */
  65.  
  66. /* NB: All macros below use a variable 'tp' pointing to the textedit struct */
  67.  
  68. /* Shorthands */
  69. #define zfocend        (tp->foc+tp->foclen)
  70. #define zgapend        (tp->gap+tp->gaplen)
  71.  
  72. /* Transformations between focpos and bufpos values */
  73. #define zaddgap(f)    ((f) < tp->gap ? (f) : (f)+tp->gaplen)
  74. #define zsubgap(pos)    ((pos) <= tp->gap ? (pos) : \
  75.              (pos) <= zgapend ? tp->gap : (pos)-tp->gaplen)
  76.  
  77. /* ++ and -- operators for bufpos variables */
  78. #define zincr(p)    (++*(p) == tp->gap ? (*(p) += tp->gaplen) : *(p))
  79. #define zdecr(p)    (*(p) == zgapend ? (*(p) = tp->gap - 1) : --*(p))
  80.  
  81. /* +1 and -1 operators for same */
  82. #define znext(p)    ((p) == tp->gap-1 ? zgapend : (p)+1)
  83. #define zprev(p)    ((p) == zgapend ? (tp->gap-1) : (p)-1)
  84.  
  85. /* Access characters at/before positions */
  86. #define zcharat(p)    (tp->buf[p])
  87. #define zcharbefore(p)    (tp->buf[zprev(p)])
  88.  
  89. /* Tab stop calculation */
  90. #define znexttab(w) ((((w)+tp->tabsize) / tp->tabsize) * tp->tabsize)
  91.  
  92. /* Functions that don't return int */
  93. TEXTEDIT *tesetup();
  94. char *zmalloc();
  95. char *zrealloc();
  96.  
  97. /* Debugging help */
  98.  
  99. #ifndef NDEBUG
  100.  
  101. #ifndef __LINE__
  102. #define __LINE__ 0
  103. #endif
  104.  
  105. /* General assertion (NB: type command-period to dprintf to halt) */
  106. #define zassert(n) ((n) || dprintf("line %d: zassert(n) failed", __LINE__))
  107.  
  108. /* Check the validity of a buffer offset */
  109. #define zcheckpos(p) \
  110.     ((p)>=0 && (p)<=tp->buflen && ((p)<tp->gap || (p)>=zgapend) || \
  111.         dprintf("line %d: zcheckpos(p=%d) buf[%d] gap=%d+%d", \
  112.             __LINE__, p, tp->buflen, tp->gap, tp->gaplen))
  113.  
  114. /* Sanity checking routine for entire state */
  115. #define zcheck() techeck(tp, __LINE__)
  116.  
  117. #else /* NDEBUG */
  118.  
  119. #define zassert(n)    /*empty*/
  120. #define zcheckpos(pos)    /*empty*/
  121. #define zcheck()    /*empty*/
  122.  
  123. #endif /* NDEBUG */
  124.